﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Web.Enhancements.Rest
{
    /// <summary>
    /// Interface that must be implemented by the class that represents the factory creating an appropriate class that 
    /// provides ability to deserialize data coming into REST services as JSON-formatted data from the client.
    /// </summary>
    public interface ICustomJsonSerializerProvider
    {
        /// <summary>
        /// Method creates and returns deserializer.
        /// </summary>
        /// <summary>
        /// Method creates and returns deserializer.
        /// </summary>
        /// <param name="targetType">The target type to deserialize to.</param>
        /// <returns>Returns an instance of an object that implements the ICustomJsonSerializer interface.</returns>
        ICustomJsonSerializer CreateJsonSerializer(Type targetType);
    }

    /// <summary>
    /// Interface that must be implemented by the class that 
    /// provides ability to deserialize data coming into REST services as JSON-formatted data from the client.
    /// </summary>
    public interface ICustomJsonSerializer
    {
        /// <summary>
        /// Method serializes data into a target type.
        /// </summary>
        /// <param name="writer">Stream writer to serialize result to.</param>
        /// <param name="objectValue">Object value being serialized.</param>
        void Serialize(System.IO.TextWriter writer, object objectValue);

        /// <summary>
        /// Method deserializes data into a target type.
        /// </summary>
        /// <param name="jsonData">Data that should be deserialized.</param>
        /// <param name="targetType">The target type to deserialize to.</param>
        /// <param name="hasContract">Boolean indicator whether class has a DataContract attribute and should be use.</param>
        /// <returns>Returns an instance of an object.</returns>
        object Deserialize(string jsonData, Type targetType, bool hasContract);
    }
}
